import { defineStore } from "pinia";

export const foldMenuStore = defineStore("foldMenu", {
  state() {
    return {
      menus: [],
      defaultActive: "",
      collapse: false,
      cached: [],
    };
  },
  actions: {
    setCollapse(collapse) {
      this.collapse = collapse;
    },
    setMenus(menus) {
      this.menus = menus;
    },
    changeDefaultActive(path) {
      this.defaultActive = path;
    },
    addCache(tag) {
      if (this.cached.some((ele) => ele.name === tag.name)) return;
      this.cached.push(tag);
    },
  },
  persist: {
    storage: sessionStorage,
    paths: ["defaultActive", "collapse", "cached"],
  },
});
